<template>
    <!-- 猜你喜欢 -->
    <div class="like">
        <div class="py-container">
            <div class="title">
                <h3 class="fl">猜你喜欢</h3>
                <a href="javascript:;" class="fr tip changeBnt">换一换</a>
            </div>
            <!--details-->
            <div class="details clearfix">
                <div class="sui-navbar">
                    <div class="navbar-inner filter">
                        <ul class="sui-nav">
                            <li class="active">
                                <a href="#">综合</a>
                            </li>
                            <li>
                                <a href="#">销量</a>
                            </li>
                            <li>
                                <a href="#">新品</a>
                            </li>
                            <li>
                                <a href="#">评价</a>
                            </li>
                            <li>
                                <a href="#">价格⬆</a>
                            </li>
                            <li>
                                <a href="#">价格⬇</a>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="goods-list">
                    <ul class="yui3-g">
                        <li class="yui3-u-1-5" v-for="(item,index) in page.records" :key="item.id">
                            <div class="list-wrap">
                                <div class="p-img">
                                    <a target="_blank">
                                        <router-link :to="`/detail/${item.id}`">
                                            <video :src="item.avatar" style="height: 200px;width: 200px" ></video>
<!--                                            <img :src="item.avatar" style="height: 200px">-->
                                        </router-link>
                                    </a>
                                </div>
                                <div class="price">
                                    <strong>
                                        <em>¥</em>
                                        <i> {{item.price}}</i>&nbsp&nbsp
                                        <el-tag type="success" v-if="item.state === 0">已上架</el-tag>
                                    </strong>
                                </div>
                                <div class="attr">
                                    <router-link :to="`/detail/${item.id}`">
                                        <a target="_blank">{{item.address+item.addressInfo+item.houseDescribe}}</a>
                                    </router-link>
                                </div>
                                <div class="commit">
                                    <i class="command">咨询电话：<span>{{item.phoneNumber}}</span></i>
                                </div>
                                <div class="operate">
                                    <button class="sui-btn btn-bordered btn-danger" @click="ToOrder(item.id,index)">订购</button>
                                </div>
                            </div>
                        </li>
                    </ul>
                </div>
                <div class="fr page">
                    <div class="sui-pagination clearfix">
                        <!--分页-->
                        <el-pagination
                                v-if="page.total > 0"
                                @size-change="handleSizeChange"
                                @current-change="handleCurrentChange"
                                :current-page="page.current"
                                :page-sizes="[5, 10, 20, 30]"
                                :page-size="page.size"
                                layout="prev"
                                :total="page.total">
                        </el-pagination>
                        <el-pagination
                                background
                                @size-change="handleSizeChange"
                                @current-change="handleCurrentChange"
                                :current-page="page.current"
                                :page-sizes="[5, 10, 20, 30]"
                                :page-size="page.size"
                                layout="total, sizes, prev, pager, next, jumper"
                                :total="page.total">
                        </el-pagination>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import {categoryList,getOrders} from '@/api/index'

    export default {
        name: "Like",
        data() {
            return {
                page: {
                    records: [],
                    total: 0,
                    size: 0,
                    current: 0,
                    orders: []
                },
                pageNum: 1,
                pageSize: 10,
                OrderForm: {
                    houseInfoId: undefined,
                    tourist: undefined,
                },
            }
        },
        created() {
            this.AllList();
            this.Check();
        },
        methods: {
            AllList() {
                categoryList(this.pageNum, this.pageSize).then(response => {
                    this.page = response.data
                })
            },
            handleSizeChange (val) {
                /* 将value赋值给size, 重新查询数据 */
                this.pageSize = val
                this.onSubmit()
            },
            handleCurrentChange (val) {
                this.pageNum = val
                this.onSubmit()
            },
            onSubmit () {
                categoryList(this.pageNum, this.pageSize).then(response => {
                    this.page = response.data
                })
            },
            Check() {
                if (Boolean(sessionStorage.getItem("LoginInfo"))) {
                    let data = JSON.parse(sessionStorage.getItem("LoginInfo"));
                    this.OrderForm.tourist = data.id;
                }
            },
            ToOrder(id,index) {
                this.OrderForm.houseInfoId = id
                getOrders(this.OrderForm).then(response => {
                    if (response.code === 200) {
                        this.RightMessage(this, '添加成功', response.message, 'success')
                        sessionStorage.setItem("ORDERINFO", JSON.stringify(this.page.records[index]))
                        this.$router.push({path: '/addsuccess'})
                    } else {
                        this.$notify.error({
                            title: '错误',
                            message: response.message
                        });
                        this.$router.push({path: '/login'})
                    }
                })
            }
        }

    }
</script>

<style scoped lang="less">
    .like {
        margin-top: 15px;

        .py-container {
            width: 1200px;
            margin: 0 auto;

            .title {
                overflow: hidden;

                .fl {
                    float: left;
                    font-size: 20px;
                    line-height: 30px;
                }

                .fr {
                    float: right;
                    background-image: url(../../assets/images/icons.png);
                    width: 66px;
                    height: 25px;
                    background-position: 182px -104px;
                    line-height: 30px;
                    font-size: 12px;
                    font-weight: 400;
                    color: #666;
                    text-decoration: none;
                }
            }

            .bd {
                .favourate {
                    border: 1px solid #e4e4e4;
                    overflow: hidden;
                    padding: 0 10px;
                    box-sizing: border-box;
                    display: flex;

                    li {
                        height: 250px;
                        margin: 0 -1px;
                        overflow: hidden;
                        background: #fff;
                        position: relative;
                        width: 16.667%;
                        display: flex;
                        flex-direction: column;
                        align-items: center;
                        cursor: pointer;

                        img {
                            width: 142px;
                            height: 142px;
                            transition: all 400ms;

                            &:hover {
                                opacity: 0.8;
                                transform: scale(1.1)
                            }
                        }

                        .like-text {
                            padding: 0;
                            width: 142px;
                            border-right: 1px solid #e4e4e4;

                            p {
                                margin: 5px 0;
                            }

                            h3 {
                                color: #df3033;
                                font-size: 20px;
                                line-height: 30px;
                                margin: 9px 0;
                                font-weight: 700;
                            }
                        }
                    }
                }
            }
        }
    }

    .details {
        margin-bottom: 5px;

        .sui-navbar {
            overflow: visible;
            margin-bottom: 0;

            .filter {
                min-height: 40px;
                padding-right: 20px;
                background: #fbfbfb;
                border: 1px solid #e2e2e2;
                padding-left: 0;
                border-radius: 0;
                box-shadow: 0 1px 4px rgba(0, 0, 0, 0.065);

                .sui-nav {
                    position: relative;
                    left: 0;
                    display: block;
                    float: left;
                    margin: 0 10px 0 0;

                    li {
                        float: left;
                        line-height: 18px;

                        a {
                            display: block;
                            cursor: pointer;
                            padding: 11px 15px;
                            color: #777;
                            text-decoration: none;
                        }

                        &.active {
                            a {
                                background: #e1251b;
                                color: #fff;
                            }
                        }
                    }
                }
            }
        }

        .goods-list {
            margin: 20px 0;

            ul {
                display: flex;
                flex-wrap: wrap;

                li {
                    height: 100%;
                    width: 20%;
                    margin-top: 10px;
                    line-height: 28px;

                    .list-wrap {
                        .p-img {
                            padding-left: 15px;
                            width: 215px;
                            height: 250px;

                            a {
                                color: #666;

                                img {
                                    max-width: 100%;
                                    height: auto;
                                    vertical-align: middle;
                                }
                            }
                        }

                        .price {
                            padding-left: 15px;
                            font-size: 18px;
                            color: #c81623;

                            strong {
                                font-weight: 700;

                                i {
                                    margin-left: -5px;
                                }
                            }
                        }

                        .attr {
                            padding-left: 15px;
                            width: 85%;
                            overflow: hidden;
                            margin-bottom: 8px;
                            min-height: 65px;
                            cursor: pointer;
                            line-height: 1.8;
                            display: -webkit-box;
                            -webkit-box-orient: vertical;
                            -webkit-line-clamp: 2;

                            a {
                                color: #333;
                                text-decoration: none;
                            }
                        }

                        .commit {
                            padding-left: 15px;
                            height: 22px;
                            font-size: 13px;
                            color: #a7a7a7;

                            span {
                                font-weight: 700;
                                color: #646fb0;
                            }
                        }

                        .operate {
                            padding: 12px 15px;

                            .sui-btn {
                                display: inline-block;
                                padding: 2px 14px;
                                box-sizing: border-box;
                                margin-bottom: 0;
                                font-size: 12px;
                                line-height: 18px;
                                text-align: center;
                                vertical-align: middle;
                                cursor: pointer;
                                border-radius: 0;
                                background-color: transparent;
                                margin-right: 15px;
                            }

                            .btn-bordered {
                                min-width: 85px;
                                background-color: transparent;
                                border: 1px solid #8c8c8c;
                                color: #8c8c8c;

                                &:hover {
                                    border: 1px solid #666;
                                    color: #fff !important;
                                    background-color: #666;
                                    text-decoration: none;
                                }
                            }

                            .btn-danger {
                                border: 1px solid #e1251b;
                                color: #e1251b;

                                &:hover {
                                    border: 1px solid #e1251b;
                                    background-color: #e1251b;
                                    color: white !important;
                                    text-decoration: none;
                                }
                            }
                        }
                    }
                }
            }
        }

        .page {
            width: 733px;
            height: 66px;
            overflow: hidden;
            float: right;

            .sui-pagination {
                margin: 18px 0;

                ul {
                    margin-left: 0;
                    margin-bottom: 0;
                    vertical-align: middle;
                    width: 490px;
                    float: left;

                    li {
                        line-height: 18px;
                        display: inline-block;

                        a {
                            position: relative;
                            float: left;
                            line-height: 18px;
                            text-decoration: none;
                            background-color: #fff;
                            border: 1px solid #e0e9ee;
                            margin-left: -1px;
                            font-size: 14px;
                            padding: 9px 18px;
                            color: #333;
                        }

                        &.active {
                            a {
                                background-color: #fff;
                                color: #e1251b;
                                border-color: #fff;
                                cursor: default;
                            }
                        }

                        &.prev {
                            a {
                                background-color: #fafafa;
                            }
                        }

                        &.disabled {
                            a {
                                color: #999;
                                cursor: default;
                            }
                        }

                        &.dotted {
                            span {
                                margin-left: -1px;
                                position: relative;
                                float: left;
                                line-height: 18px;
                                text-decoration: none;
                                background-color: #fff;
                                font-size: 14px;
                                border: 0;
                                padding: 9px 18px;
                                color: #333;
                            }
                        }

                        &.next {
                            a {
                                background-color: #fafafa;
                            }
                        }
                    }
                }

                div {
                    color: #333;
                    font-size: 14px;
                    float: right;
                    width: 241px;
                }
            }
        }
    }
</style>
